!(function($) {
  var lunbotu = function(ele, options) {
    this.el = ele;
    this.el.addClass("slider");
    this.data = options.data;
    this.items = [];
    this.length = options.data.length;
    var hSlide = '<div class="slider-inner"></div>';
    var jSlide = $(hSlide);
    jSlide.appendTo(this.el);

    for (var i = 0; i < this.length; i++) {
      console.log(this.data[i].url);
      var hImg =
        '<div class="item"><img src="' + this.data[i].url + '"></img></div>';
      this.items.push($(hImg).appendTo(jSlide));
    }
    var index=0;
    this.items[0].addClass("active");
    var hPrev = '<span class="slider-control prev">&lt;</span>';
    var hNext = '<span class="slider-control next">&gt;</span>';
    var hPrev = $(hPrev).appendTo(this.el);
    var hNext = $(hNext).appendTo(this.el);
    var self=this;
    hPrev.on("click", function() {
        index--
        $(self.el).find(".active").removeClass("active");
        self.items[index].addClass("active");
    });
    hNext.on("click", function() {
        index++

        self.el.find(".active").removeClass("active");
        console.log(self.items[index]);
        self.items[index].addClass("active");
    });
  };
  var plugin = function(option) {
    return this.each(function() {
      var jThis = $(this); //当前jquery对象
      var options = $.extend({}, jThis.data(), typeof option ? option : false); //参数
      var data = jThis.data("lunbotu");
      if (!data) {
        jThis.data("lunbotu", new lunbotu(jThis, options));
      }
      if (typeof option == "string") {
        data[option].call(data);
      }
    });
  };
  $.fn.lunbotu = plugin;
})(jQuery);
